/*
 * @Descripttion: 节流
 * @version: 1.0.0
 * @Author: shuaishuai.han
 * @Date: 2022-01-07 23:34:43
 */
export default {
  inserted: (el, binding) => {
    let timer = null;
    let flag = null;
    const arg = binding.arg || 'click';
    el.addEventListener(arg, () => {
      if (!flag) {
        flag = true;
        typeof binding.value === 'function' && binding.value();
        timer && clearTimeout(timer);
        timer = setTimeout(() => {
          flag = false;
        }, 2000);
      }
    });
  }
};
